<include file="Common/header" />
<!-- 导航栏 -->
{$bread_crumb}
<!-- 导航栏 -->
<div class="page-container">
    <form action="{:U(CONTROLLER_NAME.'/update')}" method="post" class="form form-horizontal" enctype="multipart/form-data" onsubmit="return submit_before()">
        <input type="hidden" name="id" value="{$data['id']}">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>角色名称</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="" name="m[title]" value="{$data['title']}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>描述</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="" name="m[description]" value="{$data['description']}" >
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">权限列表：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <foreach name="rules" item="item">
                    <dl class="permission-list">
                        <dt>
                            <label>{$item['title']}</label>
                        </dt>
                        <dd>
                            <dl class="cl permission-list2">
                                <dt>
                                    <label class="">
                                        <input type="checkbox" name="rules[]" value="{$item['id']}" <if condition="in_array($item['id'], $data['rules'])">checked</if> >
                                        {$item['title']}</label>
                                </dt>
                                <if condition="item.childs">
                                    <dd>
                                        <foreach name="item['childs']" item="it">
                                            <label class="">
                                            <input type="checkbox" name="rules[]" value="{$it['id']}" <if condition="in_array($it['id'], $data['rules'])">checked</if>>
                                            {$it['title']}</label>
                                        </foreach>
                                    </dd>
                                </if>
                            </dl>
                        </dd>
                    </dl> 
                </foreach>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存并提交审核</button>
                <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
<include file="Common/footer" />
<script type="text/javascript">
/*checkbox*/
$(function(){
    $(".permission-list dt input:checkbox").click(function(){
        $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
    });
    $(".permission-list2 dd input:checkbox").click(function(){
        var l =$(this).parent().parent().find("input:checked").length;
        var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
        if($(this).prop("checked")){
            $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
            $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
        }
        else{
            if(l==0){
                $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
            }
            if(l2==0){
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
            }
        }
    });
});
/*表单提交之前的操作，主要针对一些数据类型*/
function submit_before() {
    $('#e_text').val(UE.getEditor('editor').getContent());
}


</script> 